//
//  AppealDetailController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/8/3.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "AppealDetailController.h"
#import "TypeCell.h"
@interface AppealDetailController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *codeLabel;

@property (weak, nonatomic) IBOutlet UILabel *shenqLabel;
@property (weak, nonatomic) IBOutlet UILabel *bumenLabel;
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *headViewHeight;

@end

@implementation AppealDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"诉求详情";
    self.nameLabel.text = [NSString stringWithFormat:@"%@提交的%@",self.model.real_name,self.model.type_name];
    self.codeLabel.text = self.model.appeal_code;
    self.shenqLabel.text = self.model.real_name;
    self.bumenLabel.text = self.model.section_name;
    self.timeLabel.text = [self ConvertStrToTime:self.model.create_time];
    self.typeLabel.text = self.model.type_name;
    self.contentLabel.text = self.model.content;
    
//    if (self.model.more.photos.count >0||self.model.more==nil) {
//        self.headViewHeight.constant = 230;
//       }else{
//        self.headViewHeight.constant = 150;
//       }
    if (self.model.more==nil) {
           self.headViewHeight.constant = 150;
          }else{
           self.headViewHeight.constant = 230;
          }
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    UICollectionViewFlowLayout *flow1 = [[UICollectionViewFlowLayout alloc] init];
    [flow1 setScrollDirection:UICollectionViewScrollDirectionHorizontal];//竖直滑动
    flow1.itemSize = CGSizeMake(70, 70);
    self.collectionView.delegate = self;
      flow1.sectionInset = UIEdgeInsetsMake(1.0, 1.0, 1.0, 1.0);
    self.collectionView.dataSource = self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.collectionViewLayout = flow1;
    [self.collectionView registerNib:[UINib nibWithNibName:@"TypeCell" bundle:nil] forCellWithReuseIdentifier:@"TypeCell4"];//注册cel
    
       
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    //    return self.treeList.count;
    return self.model.more.photos.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TypeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TypeCell4" forIndexPath:indexPath];
    PhotosModel *model = self.model.more.photos[indexPath.row];
    
    //    [cell.backImageView sd_setImageWithURL:[NSURL URLWithString:@"%@%@",BaseImgUrl,model.url]];
    
    NSString * str1 = @"\\";
    NSString  *imageUrl = [model.url stringByReplacingOccurrencesOfString:str1 withString:@"/"];
    [cell.backImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseImgUrl,imageUrl]]];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    //      PhotosModel *model = self.model.more.photos[indexPath.row];
    [self selectedIndex:indexPath.row withImageURLs:self.model.more.photos];
}

- (void)selectedIndex:(NSInteger)index withImageURLs:(NSArray *)urlsArray{
    NSMutableArray *datas = [NSMutableArray array];

    for (PhotosModel *model in urlsArray) {
        YBIBImageData *data = [YBIBImageData new];
        NSString * str1 = @"\\";
        NSString  *imageUrl = [model.url stringByReplacingOccurrencesOfString:str1 withString:@"/"];
        data.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BaseImgUrl,imageUrl]];
        [datas addObject:data];
    }
    YBImageBrowser *browser = [YBImageBrowser new];
    browser.dataSourceArray = datas;
    browser.currentPage = index;
    [browser show];
}



//时间戳变为格式时间
- (NSString *)ConvertStrToTime:(NSString *)timeStr{
    
    long long time=[timeStr longLongValue];
    //    如果服务器返回的是13位字符串，需要除以1000，否则显示不正确(13位其实代表的是毫秒，需要除以1000)
    //    long long time=[timeStr longLongValue] / 1000;
    
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSString*timeString=[formatter stringFromDate:date];
    
    return timeString;
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
